package org.example.node;

/**
 * @author liyishan
 * @date 2024/2/29 09:59
 * @apiNote
 */

public class Test00083DeleteDuplicates {

    /**
     * 只删除重复后多出来的  1 1  2 -> 1 2
     * @param head
     * @return
     */
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null){
            return head;
        }
        ListNode cur = head;
        while(cur.next != null){
            if(cur.val == cur.next.val){
                cur.next = cur.next.next;
            }else{
                cur = cur.next;
            }
        }
        return head;
    }

    /**
     * 删除所有重复了的   1 1 2 -> 2
     * @param head
     * @return
     */
    public ListNode deleteDuplicates1(ListNode head) {
        if(head == null){
            return null;
        }
        ListNode res = new ListNode(0);
        res.next = head;
        ListNode cur= res;
        while(cur.next != null && cur.next.next != null){
            if(cur.next.val == cur.next.next.val){
                int temp = cur.next.val;
                while(cur.next != null && cur.next.val == temp){
                    cur.next = cur.next.next;
                }
            }else{
                cur = cur.next;
            }
        }
        return res.next;
    }

}
